/*
 * @Author: 吴世扬 18368095041@163.com
 * @Date: 2022-09-23 16:33:50
 * @LastEditors: 吴世扬 18368095041@163.com
 * @LastEditTime: 2022-10-12 09:52:46
 * @FilePath: /vue3-datav/vite.config.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { fileURLToPath, URL } from 'node:url';
import path from 'path';
import { defineConfig, type UserConfigExport } from 'vite';
import vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';
import VueSetupExtend from 'vite-plugin-vue-setup-extend';

// https://vitejs.dev/config/
const configCreator: (config: { mode: string }) => UserConfigExport = ({ mode }) => {
    // const env = loadEnv(mode, process.cwd());
    return defineConfig({
        base: mode === 'production' ? './' : '/',
        plugins: [
            VueSetupExtend(),
            vue(),
            vueJsx(),
            createSvgIconsPlugin({
                // 指定需要缓存的图标文件夹
                iconDirs: [path.resolve(process.cwd(), 'src/assets/svgs')],
                // 指定symbolId格式
                symbolId: 'icon-[name]' // 'icon-[dir]-[name]'
            })
        ],
        // build: {
        //     terserOptions: {
        //         compress: {
        //             drop_debugger: mode !== 'development'
        //         }
        //     }
        // },
        // server: {
        //     proxy: {
        //         [env.VUE_APP_BASE_API]: {
        //             // target: `https://tzt.cskj-test.top/admin/v1`,
        //             target: env.VUE_APP_BASE_URL,
        //             changeOrigin: true,
        //             pathRewrite: {
        //                 ['^' + env.VUE_APP_BASE_API]: ''
        //             }
        //         }
        //     }
        // },
        resolve: {
            alias: {
                '@': fileURLToPath(new URL('./src', import.meta.url))
            },
            extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
        },
        css: {
            preprocessorOptions: {
                scss: {
                    additionalData: '@import "@/assets/styles/variables.scss";'
                }
            }
        }
    });
};

export default configCreator;
